<script setup lang="ts">
import { ref } from 'vue'
import axios from 'axios';
import {useRouter} from 'vue-router'
const router = useRouter();

function doadmin(){
    axios.get('api/admin/api')
    .then((res:any)=>{
        console.log(res)
       if(res.data == 'admin'){
           router.push('/admin')
       }
    })
    .catch((err)=>{
        console.log(err);
        alert(err.message)
    })
}
function douser(){
    axios.get('api/user/api')
    .then((res:any)=>{
        console.log(res)
       if(res.data == 'user'){
           router.push('/user')
       }
    })
    .catch((err)=>{
        console.log(err);
        alert(err.message)
    })
}
function doapp(){
    axios.get('api/app/api')
    .then((res:any)=>{
        console.log(res)
       if(res.data == 'app'){
           router.push('/app')
       }
    })
    .catch((err)=>{
        console.log(err);
        alert(err.message)
    })
}
function doout(){
    axios.post('api/logout')
    .then((res:any)=>{
        console.log(res)
    })
    .catch((err)=>{
        console.log(err);
        if(err.code == "ERR_NETWORK"){
           router.push('/login')
       }
    })
}
</script>

<template>
系统首页<br>

<button @click="doadmin">admin</button>
<button @click="douser">user</button>
<button @click="doapp">app</button><br>
<button @click="doout">退出登录</button>

</template>

<style scoped>
</style>
